﻿SP.UI.TileView.TileRenderer.prototype = {
    context: null,
    id: null,
    title: null,
    imageUrl: null,
    size: 0,
    imageWidth: null,
    imageHeight: null,
    item: null,
    isCustomData: false,
    inError: false,
    onTilePreRender: function SP_UI_TileView_TileRenderer$onTilePreRender(builder) {
    },
    onTilePostRender: function SP_UI_TileView_TileRenderer$onTilePostRender(builder) {
    },
    onTileContentPreRender: function SP_UI_TileView_TileRenderer$onTileContentPreRender(builder) {
    },
    onTileContentPostRender: function SP_UI_TileView_TileRenderer$onTileContentPostRender(builder) {
    },
    renderBackgroundImage: function SP_UI_TileView_TileRenderer$renderBackgroundImage(builder) {
        // OWA 
        if (this.item.ServerRedirectedEmbedUrl.length > 0) {
            var wopiUrl = this.item.ServerRedirectedEmbedUrl.replace("interactivepreview", "embedview");
            builder.addAttribute('src', STSHtmlEncode(wopiUrl));
            builder.addAttribute('id', SP.UI.TileView.TileRenderer.tileElementId(this.context, this.id, 7));
            builder.addAttribute('alt', STSHtmlEncode(this.title));
            builder.addAttribute('width', 150);
            builder.addAttribute('height', 150);
            builder.renderBeginTag('iframe');
            builder.renderEndTag();
        } else {
            if (!SP.ScriptHelpers.isNullOrUndefinedOrEmpty(this.imageUrl)) {
                builder.addAttribute('src', STSHtmlEncode(this.imageUrl));
            }
            else {
                builder.addAttribute('src', '/_layouts/15/images/blank.gif');
            }

            builder.addAttribute('id', SP.UI.TileView.TileRenderer.tileElementId(this.context, this.id, 7));
            builder.addAttribute('alt', STSHtmlEncode(this.title));
            var $v_0 = !SP.ScriptHelpers.isNullOrUndefined(this.context.CurrentItem) ? this.context.CurrentItem['FSObjType'] : '0';

            builder.addAttribute('onerror', 'displayGenericDocumentIcon(event.srcElement ? event.srcElement : event.target, ' + $v_0 + '); return false;');
            builder.addAttribute('onload', '(event.srcElement ? event.srcElement : event.target).style.visibility = \'visible\'; SP.ScriptHelpers.resizeImageToSquareLength(this, ' + this.size + ')');
            builder.renderBeginTag('img');
            builder.renderEndTag();
        }
    },
    render: function SP_UI_TileView_TileRenderer$render() {
        var $v_0 = new SP.HtmlBuilder();

        this.onTilePreRender($v_0);
        $v_0.addAttribute('id', SP.UI.TileView.TileRenderer.tileElementId(this.context, this.id, 1));
        $v_0.addCssClass('ms-tileview-tile-root');
        $v_0.addAttribute('style', String.format('width: {0}px; height: {0}px;', this.size + 10));
        $v_0.renderBeginTag('div');
        this.onTileContentPreRender($v_0);
        $v_0.addAttribute('id', SP.UI.TileView.TileRenderer.tileElementId(this.context, this.id, 2));
        $v_0.addCssClass('ms-tileview-tile-content');
        $v_0.addAttribute('style', String.format('width: {0}px; height: {0}px;', this.size));
        $v_0.addAttribute('aria-haspopup', 'true');
        $v_0.renderBeginTag('div');
        this.onBackgroundPreRender($v_0);
        this.renderBackgroundImage($v_0);
        $v_0.addAttribute('id', SP.UI.TileView.TileRenderer.tileElementId(this.context, this.id, 4));
        $v_0.addCssClass('ms-tileview-tile-detailsBox');
        $v_0.addAttribute('style', String.format('width: {0}px; height: {0}px;', this.size));
        $v_0.addAttribute('offy', '' + (this.size - this.get_$n_0()));
        $v_0.renderBeginTag('div');
        this.$13_0($v_0);
        $v_0.renderEndTag();
        this.onBackgroundPostRender($v_0);
        $v_0.renderEndTag();
        this.onTileContentPostRender($v_0);
        $v_0.renderEndTag();
        this.onTilePostRender($v_0);
        return $v_0.toString();
    },
    $13_0: function SP_UI_TileView_TileRenderer$$13_0($p0) {
        var $v_0 = 'Medium';

        $p0.addCssClass('ms-noList');
        $p0.addCssClass('ms-tileview-tile-detailsList' + $v_0);
        $p0.renderBeginTag('ul');
        $p0.addAttribute('id', SP.UI.TileView.TileRenderer.tileElementId(this.context, this.id, 5));
        $p0.addCssClass('ms-tileview-tile-title' + $v_0);
        $p0.addCssClass('ms-tileview-tile-title' + $v_0 + 'Collapsed');
        $p0.addAttribute('Collapsed', 'ms-tileview-tile-title' + $v_0 + ' ' + 'ms-tileview-tile-' + 'title' + $v_0 + 'Collapsed');
        $p0.addAttribute('Expanded', 'ms-tileview-tile-title' + $v_0 + ' ' + 'ms-tileview-tile-' + 'title' + $v_0 + 'Expanded');
        $p0.renderBeginTag('li');
        $p0.addCssClass('ms-tileview-tile-titleText' + $v_0 + 'Collapsed');
        $p0.addAttribute('Collapsed', 'ms-tileview-tile-titleText' + $v_0 + 'Collapsed');
        $p0.addAttribute('Expanded', 'ms-tileview-tile-titleText' + $v_0 + 'Expanded');
        $p0.renderBeginTag('div');
        $p0.addAttribute('title', this.title);
        $p0.write(this.title);
        $p0.renderEndTag();
        $p0.renderEndTag();
        $p0.addCssClass('ms-tileview-tile-description' + $v_0);
        $p0.addAttribute('id', SP.UI.TileView.TileRenderer.tileElementId(this.context, this.id, 6));
        $p0.renderBeginTag('li');
        $p0.write(this.get_tileDescription());
        $p0.renderEndTag();
        $p0.renderEndTag();
    },
    get_$n_0: function SP_UI_TileView_TileRenderer$get_$n_0() {
        return Math.floor(this.size / 3);
    }
};

SP.UI.TileView.TabularTileRenderer.prototype = {
    onTilePreRender: function SP_UI_TileView_TabularTileRenderer$onTilePreRender(builder) {
        var $v_0 = !SP.ScriptHelpers.isNullOrUndefinedOrEmpty(this.context.ListSchema.group1) ? this.item[this.context.ListSchema.group1 + '.newgroup'] : '';
        var $v_1 = !SP.ScriptHelpers.isNullOrUndefinedOrEmpty(this.context.ListSchema.group2) ? this.item[this.context.ListSchema.group2 + '.newgroup'] : '';

        if (!this.context.CurrentItemIdx || SP.ScriptHelpers.isNullOrUndefinedOrEmpty(this.context.ListSchema.group1) && $v_0 === '1' || SP.ScriptHelpers.isNullOrUndefinedOrEmpty(this.context.ListSchema.group2) && $v_0 === '2') {
            builder.write('<tr><td colspan=\"30\"><div>');
        }
    },
    onTilePostRender: function SP_UI_TileView_TabularTileRenderer$onTilePostRender(builder) {
        var $v_0 = this.context.ListData['Row'];
        var $v_1 = this.context.ListData['LastRow'];
        var $v_2 = this.context.CurrentItemIdx + 1;
        var $v_3 = $v_2 < $v_1 ? $v_0[$v_2] : null;
        var $v_4 = !SP.ScriptHelpers.isNullOrUndefined($v_3) && !SP.ScriptHelpers.isNullOrUndefinedOrEmpty(this.context.ListSchema.group1) ? $v_3[this.context.ListSchema.group1 + '.newgroup'] : '';
        var $v_5 = !SP.ScriptHelpers.isNullOrUndefined($v_3) && !SP.ScriptHelpers.isNullOrUndefinedOrEmpty(this.context.ListSchema.group2) ? $v_3[this.context.ListSchema.group2 + '.newgroup'] : '';

        if (SP.ScriptHelpers.isNullOrUndefined($v_3) || SP.ScriptHelpers.isNullOrUndefinedOrEmpty(this.context.ListSchema.group1) && $v_4 === '1' || SP.ScriptHelpers.isNullOrUndefinedOrEmpty(this.context.ListSchema.group2) && $v_4 === '2') {
            builder.write('</div></td></tr>');
        }
    },
    onTileContentPreRender: function SP_UI_TileView_TabularTileRenderer$onTileContentPreRender(builder) {
        var $v_0 = this.item['ID'];
        var $v_1 = GenerateIID(this.context);

        builder.addCssClass('ms-tileview-tile-inner');
        builder.addAttribute('id', $v_1);
        builder.addAttribute('iid', $v_1);
        builder.addAttribute('style', String.format('width: {0}px; height: {0}px;', this.size));
        builder.renderBeginTag('div');
    },
    onTileContentPostRender: function SP_UI_TileView_TabularTileRenderer$onTileContentPostRender(builder) {
        var $v_0 = this.$r_1(this.context);
        var $v_1 = this.context.ListSchema.TabularView === '1' && this.$K_1;

        if ($v_0 || $v_1) {
            var $v_2 = GenerateIID(this.context);

            builder.addCssClass('ms-tileview-tile-tabularBox ms-hide');
            builder.renderBeginTag('div');
            if ($v_1 && !(this.isCustomData || this.inError)) {
                var $v_3 = SP.UI.TileView.TileRenderer.tileElementId(this.context, this.id, 8);

                builder.addAttribute('id', $v_3);
                builder.addAttribute('onclick', 'this.checked = !this.checked; SP.UI.TileView.Utilities.selectListItem(\'' + STSScriptEncode($v_2) + '\', this.checked);');
                builder.addAttribute('href', 'javascript:{}');
                builder.addAttribute('title', STSHtmlEncode(Strings.STS.L_SPSelection_Checkbox));
                builder.addCssClass('ms-floatLeft');
                builder.addCssClass('s4-itm-selected');
                builder.addCssClass('ms-tileview-tile-selectionBox');
                builder.addAttribute('data-sp-continueWPSelect', 'true');
                builder.renderBeginTag('a');
                builder.addCssClass('s4-itm-cbx s4-itm-imgCbx');
                builder.renderBeginTag('span');
                builder.addCssClass('s4-itm-imgCbx-inner');
                builder.renderBeginTag('span');
                builder.addCssClass('ms-selectitem-span');
                builder.renderBeginTag('span');
                builder.addCssClass('ms-selectitem-icon');
                builder.addAttribute('src', GetThemedImageUrl('spcommon.png'));
                builder.addAttribute('alt', STSHtmlEncode(Strings.STS.L_SPSelection_Checkbox));
                builder.renderBeginTag('img');
                builder.renderEndTag();
                builder.renderEndTag();
                builder.renderEndTag();
                builder.renderEndTag();
                builder.renderEndTag();
            }
            if ($v_0 && !(this.isCustomData || this.inError)) {
                builder.write(this.$11_1(this.context, this.context.CurrentItem));
            }
            builder.renderEndTag();
        }
        builder.addCssClass('ms-hide');
        builder.addAttribute('id', this.get_$X_1());
        builder.renderBeginTag('div');
        // OWA 
        var url = ComputedFieldWorker.NameOrTitle(this.context, null, this.context.CurrentItem, this.context.ListSchema)
        if (this.context.CurrentItem.ServerRedirectedEmbedUrl.length > 0) {
            url = url.replace("");
            builder.write(this.context.CurrentItem.ServerRedirectedEmbedUrl);
        } else {
            builder.write(url);
        }
        builder.renderEndTag();
        builder.renderEndTag();
    },
    onBackgroundPreRender: function SP_UI_TileView_TabularTileRenderer$onBackgroundPreRender(builder) {
        var $v_0 = this.item['ID'];
        var $v_1 = GenerateIID(this.context);

        builder.addAttribute('id', SP.UI.TileView.TileRenderer.tileElementId(this.context, $v_0, 3));
        builder.addAttribute('href', '#');
        if (!(this.isCustomData || this.inError)) {
            builder.addAttribute('onclick', 'SP.UI.TileView.Utilities.itemLinkNavigate(\'' + STSScriptEncode($v_1) + '\',\'' + STSScriptEncode(this.get_$X_1()) + '\');return false;');
        }
        builder.renderBeginTag('a');
    },
    onBackgroundPostRender: function SP_UI_TileView_TabularTileRenderer$onBackgroundPostRender(builder) {
        builder.renderEndTag();
    },
    $11_1: function SP_UI_TileView_TabularTileRenderer$$11_1($p0, $p1) {
        this.item['RenderCalloutWithoutHover'] = true;
        return RenderCalloutMenu($p0, $p1, $p0.CurrentFieldSchema, '');
    },
    $K_1: false,
    get_renderSelectionControlForTabular: function SP_UI_TileView_TabularTileRenderer$get_renderSelectionControlForTabular() {
        return this.$K_1;
    },
    set_renderSelectionControlForTabular: function SP_UI_TileView_TabularTileRenderer$set_renderSelectionControlForTabular(value) {
        this.$K_1 = value;
        return value;
    },
    $b_1: false,
    $a_1: false,
    $r_1: function SP_UI_TileView_TabularTileRenderer$$r_1($p0) {
        if (!this.$b_1) {
            if (!SP.ScriptHelpers.isNullOrUndefined($p0.ListSchema) && !SP.ScriptHelpers.isNullOrUndefined($p0.ListSchema.Field)) {
                for (var $v_0 = 0; $v_0 < $p0.ListSchema.Field.length; $v_0++) {
                    var $v_1 = $p0.ListSchema.Field[$v_0].CalloutMenu;

                    if (!SP.ScriptHelpers.isNullOrUndefinedOrEmpty($v_1)) {
                        this.$a_1 = $v_1.toUpperCase() === 'TRUE';
                        break;
                    }
                }
            }
            this.$b_1 = true;
        }
        return this.$a_1;
    },
    get_$X_1: function SP_UI_TileView_TabularTileRenderer$get_$X_1() {
        return SP.UI.TileView.TileRenderer.tileElementId(this.context, this.id, 9);
    }
};